#include "face_detection.hpp"
#include <string>

const std::string haarcascade_file = "/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml";

std::vector<cv::Rect> face_detection(cv::Mat img, cv::Size min_size) {
    // 加载分类器
    static cv::CascadeClassifier face_detector;
    if (face_detector.empty()) {
        face_detector.load(haarcascade_file);
    }

    // 转换为灰度
    cv::Mat img_grayscale;
    cv::cvtColor(img, img_grayscale, cv::COLOR_BGR2GRAY);

    std::vector<cv::Rect> ans;
    face_detector.detectMultiScale(img_grayscale, ans, 1.1, 4, cv::CASCADE_FIND_BIGGEST_OBJECT|cv::CASCADE_DO_ROUGH_SEARCH, min_size);
    return ans;
}